package cn.tedu.oa.seal.service.Impl;

import cn.tedu.oa.seal.mapper.SealMapper;
import cn.tedu.oa.seal.pojo.dto.SealQuery;
import cn.tedu.oa.seal.pojo.dto.SealSaveParam;
import cn.tedu.oa.seal.pojo.entity.Seal;
import cn.tedu.oa.seal.pojo.vo.SealVO;
import cn.tedu.oa.seal.service.SealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j

public class SealServiceImpl implements SealService {
    @Autowired
    SealMapper sealMapper;

    @Override
    public List<SealVO> select(SealQuery sealQuery) {
        log.info("SealServiceImpl.select()");
        List<SealVO> list = sealMapper.select(sealQuery);
        return list;
    }

    @Override
    public void save(SealSaveParam sealSaveParam) {
        log.info("SealServiceImpl.save()");
        Seal seal = new Seal();
        BeanUtils.copyProperties(sealSaveParam,seal);
        if (seal.getId()==null){
            log.info("新增"+seal);
            seal.setRegisteredDate(new Date());
            sealMapper.insert(seal);
        }else {
            log.info("修改"+seal);
            seal.setLastUsedDate(new Date());
            sealMapper.update(seal);
        }

    }

    @Override
    public void delete(Integer id) {
        log.debug("删除业务，参数：{}",id);
        sealMapper.delete(id);
    }
}
